/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import java.io.IOException;
import javax.microedition.lcdui.Image;

/**
 *
 * @author Administrator
 */
public class Library {

    private int canvasWidth;
    private int canvasHeight;
    private Image topBarImage;
    private Image bottomBarImage;
    private Image loadingImage;
    private Image handCurseurImage;
    private Image cardImages;
    private Image darkBackground;
    private Image avatar;
    private MenuObject subMenu;
    private CustomTextBox chatBox;
    private static Library library;
    private ShortShowBox[] messengerBox;

    public Library(int canvasWidth, int canvasHeight) {
        this.canvasHeight = canvasHeight;
        this.canvasWidth = canvasWidth;
    }

    public static Library getInstance(int canvasWidth, int canvasHeight) {
        if (library == null) {
            library = new Library(canvasWidth, canvasHeight);
        }
        return library;
    }

    public Image getTopBarImage() throws IOException {
        if (topBarImage == null) {
            Image topBarPiece = Utils.loadImage("top_bar_piece.png");
            topBarImage = Utils.creatImageFromPiece(topBarPiece, 1, canvasWidth);
        }
        return topBarImage;
    }

    public Image getBottomBarImage() throws IOException {
        if (bottomBarImage == null) {
            Image bottomBarPiece = Utils.loadImage("bottom_bar_piece.png");
            bottomBarImage = Utils.creatImageFromPiece(bottomBarPiece, 1, canvasWidth);
        }
        return bottomBarImage;
    }

    public Image getLoadingImage() throws IOException {
        if (loadingImage == null) {
            loadingImage = Utils.loadImage("loading.png");
        }
        return loadingImage;
    }

    public MenuObject getSubMenu() {
        if (subMenu == null) {
            subMenu = new MenuObject();
        }
        return subMenu;
    }

    public Image getHandCurSeur() throws IOException {
        if (handCurseurImage == null) {
            handCurseurImage = Utils.loadImage("hand_curseur.png");
        }
        return handCurseurImage;
    }

    public CustomTextBox getChatBox(boolean keyPad) {
        if (chatBox == null) {
            chatBox = new CustomTextBox(PiPoDesigner.COLOR_BLACK, PiPoDesigner.COLOR_WHITE, false, keyPad);
            chatBox.setFocus(true);
            chatBox.setShowTypeInput(false);
        }
        return chatBox;
    }

    public ShortShowBox[] getMessengerBox() {
        if (messengerBox == null) {
            initMessengerBox();
        }
        return messengerBox;
    }

    private void initMessengerBox() {
        messengerBox = new ShortShowBox[4];
        for (int i = 0; i < 4; i++) {
            messengerBox[i] = new ShortShowBox();
        }
    }

    public Image getCardImage() throws IOException {
        if (cardImages == null) {
            cardImages = Utils.loadImage("card.png");
        }
        return cardImages;
    }

    public Image getDarkBg() throws IOException {
        if (darkBackground == null) {
            darkBackground = Utils.loadImage("darkBg.png");
        }
        return darkBackground;
    }

    public Image getAvatar() throws IOException {
        if (avatar == null) {
            avatar = Utils.loadImage("avatar.png");
        }
        return avatar;
    }
}